package io.shallwe._admin.basedata.scanner;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;

import io.shallwe._admin.permission.Remark;
import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Account;
import io.shallwe.common.model.Scanner;

/**
 * 扫描枪信息维护
 * 包含手动扫描枪与自动扫描枪
 * @author 王小伟
 * @email shallwe_wang@foxmail.com
 * @date 2019-06-13 18:06:13
 *
 */
public class ScannerController extends BaseController{

	@Inject ScannerService service;
	
	public void index() {
		render("scanner.html");
	}
	
	public void list() {
		Integer offset = getParaToInt("offset",1);
        Integer pageSize = getParaToInt("pageSize",100);
		renderJson(service.paginate(offset, pageSize));
	}
	
	public void add() {
		render("add_edit.html");
	}
	@Before(ScannerValidator.class)
	public void save() {
		Scanner scanner =getBean(Scanner.class,"scanner",true);
		renderJson(service.save(scanner));
	}
	
	
	@Remark("编辑扫描枪")
	public void edit() {
		Integer id=getInt("id");
		Scanner scanner = service.findById(id);
		set("scanner",scanner);
		render("add_edit.html");
	}
	
	@Before(ScannerValidator.class)
	@Remark("更新编辑后的扫描枪数据")
	public void update() {
		Scanner scanner =getBean(Scanner.class,"scanner",true);
		renderJson(service.update(scanner));
	}
	
	@Remark("删除扫描枪")
	public void delete() {
		String id=get("id");
		renderJson(service.delete(id));
	}
	
	@Remark("禁用扫描枪")
	public void lock() {
		Integer id=getInt("id");
		renderJson(service.lock(id));
	}
	
	@Remark("启用扫描枪")
	public void unlock() {
		Integer id=getInt("id");
		renderJson(service.unlock(id));
	}
	
	@Remark("绑定员工号编辑页面")
	public void bindAccount() {
		Integer id=getInt("id");
		set("scannerId",id);
		render("bindAccount.html");
	}
	
	@Remark("绑定员工号提交操作")
	public void doBindAccount(){
		Integer id=getInt("scannerId");
		String employeeNumber=get("employeeNumber");
		renderJson(service.bindAccount(id,employeeNumber));
	}

	@Remark("生成员工号二维码以绑定扫描枪")
	public void showEmployeeNumberQcode(){
		Account loginAccount = getLoginAccount();
		setAttr("employeeNumber",loginAccount.getEmployeeNo());
		render("show_employeeNumber_qrcode.html");
	}
}
